package com.wetool.wechat.service;

import com.wetool.wechat.model.official.MessageType;
import com.wetool.wechat.model.official.message.AbstractMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class MessageHandlerService {
    private static final Logger LOGGER = LoggerFactory.getLogger(MessageHandlerService.class);

    @Autowired
    private EventHandlerService eventHandler;

    /**
     * @param xmlElements
     */
    public AbstractMessage dispatchMessage(Map<String, Object> xmlElements) {
        MessageType messageType = MessageType.valueOf((String) xmlElements.get("MsgType"));

        switch (messageType) {
            case event:
                LOGGER.info("接收到事件消息");
                return this.eventHandler.dispatchEvent(xmlElements);
            case text:
                LOGGER.info("接收到文本消息");
                return this.textMessageHandler(xmlElements);
            case image:
                LOGGER.info("接收到图片消息");
                return this.imageMessageHandler(xmlElements);
            case voice:
                LOGGER.info("接收到语言消息");
                return this.voiceMessageHandler(xmlElements);
            case video:
                LOGGER.info("接收到视频消息");
                return this.videoMessageHandler(xmlElements);
            case shortvideo:
                LOGGER.info("接收到短视频消息");
                return this.shortVideoMessageHandler(xmlElements);
            case location:
                LOGGER.info("接收到位置消息");
                return this.locationMessageHandler(xmlElements);
            case link:
                LOGGER.info("接收到链接消息");
                return this.linkMessageHandler(xmlElements);
        }
        return null;
    }

    private AbstractMessage linkMessageHandler(Map<String, Object> xmlElements) {
        //TODO

        return null;
    }

    private AbstractMessage locationMessageHandler(Map<String, Object> xmlElements) {
        //TODO

        return null;
    }

    private AbstractMessage shortVideoMessageHandler(Map<String, Object> xmlElements) {
        //TODO

        return null;
    }

    private AbstractMessage videoMessageHandler(Map<String, Object> xmlElements) {
        //TODO

        return null;
    }

    private AbstractMessage voiceMessageHandler(Map<String, Object> xmlElements) {
        //TODO
        return null;

    }

    private AbstractMessage imageMessageHandler(Map<String, Object> xmlElements) {

        //TODO
        return null;
    }

    private AbstractMessage textMessageHandler(Map<String, Object> xmlElements) {

        //TODO
        return null;
    }


}
